// pages/allOrder/allOrder.js
var  app = getApp(); 
Page({

  /**
   * 页面的初始数据
   */
  data: {
    oldStart: 31,
    len: 30
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var status = options.status;
    this.setData({
      status: status
    })
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var sign = wx.getStorageSync("sign");
    var status = that.data.status;
    var len = that.data.len;

    wx.request({
      url: app.globalData.ydnBase + '/index.php/Weshop/SApi/index/m/getOrderList/key/2sdfdd332342341dddff46e189670/wid/39/sign/' + sign,
      data: {
        status: status,
        start: 0,
        len: len
      },
      success: function (res) {
        console.log("订单", res);
        if(res.data.datas.status){
          var pic_domain = res.data.datas.pic_domain;
          var statusTxt = res.data.datas.statusTxt;
          var orderList = res.data.datas.orderList;
          wx.setNavigationBarTitle({
            title: statusTxt,
          })
          that.setData({
            pic_domain: pic_domain,
            orderList: orderList
          })
        }
      }
    }) 
  },
  toDetail:function(e){
    console.log(e);
    var order_id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../orderDetail/orderDetail?id=' + order_id,
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var sign = wx.getStorageSync("sign");
    var status = that.data.status;
    var oldStart = that.data.oldStart;
    var len = that.data.len;
    

    wx.request({
      url: app.globalData.ydnBase + '/index.php/Weshop/SApi/index/m/getOrderList/key/2sdfdd332342341dddff46e189670/wid/39/sign/' + sign,
      data: {
        status: status,
        start: oldStart,
        len: len
      },
      success: function (res) {
        console.log("下拉订单", res);
        if (res.data.datas.status) {
          var oldList = that.data.orderList;
          var orderList = res.data.datas.orderList;
          if(orderList){
            oldStart = oldStart + len;
            orderList = oldList.concat(orderList);
            that.setData({
              orderList: orderList,
              oldStart: oldStart
            })
          }else{
            wx.showToast({
              title: '没有更多了',
            })
          }
          
        }
      }
    }) 
  }
})